#!/usr/bin/perl -w # useful for syntax highlighting
package clreqd_modules;

#########################################################################
# This will return REPLICATED if the current storage type for		#
# the application in question is a replicated type. This means that	#
# the application build routines will not complain if the 		#
# volume groups in question are active on the nodes - since they	#
# really need to be for replicated storage.				#
#########################################################################
use strict;
use lvm;
use Data::Dumper;
use cldb;

sub ss_replicated {
my %ARGS=@_;
my $application=$ARGS{APPLICATION};

	my $CLDB=new cldb("$::ENV{TRUECL_CFG}/config.db");
	if(!defined($CLDB)) {
		return "ERROR Unable to connect to 'config' database.";
	}
	my $res=$CLDB->get_rows("SELECT * FROM applications WHERE name = '$application';");
	if(!defined($res->[0]->{nodes})) {
		return "ERROR Application '$application' is unknown.";
	}

	$CLDB->disconnect; $CLDB=undef;
	my $s=$res->[0]->{storage};
	#################################################################
	# Now open open the configuration database to get the storage	#
	# spec and list of volume groups...				#
	#################################################################

	if(! -f "$::ENV{TRUECL_CODE}/lib/storage_spec/$s.pm") {
		return "ERROR - Storage spec '$s' not available.";
	}

	eval "use storage_spec::$s;";
	my $STORAGE=eval "new storage_spec::$s;";
	if(!defined($STORAGE)) {
		return "ERROR Unable to use storage spec - storage_spec::$s\nError: " . eval "storage_spec::${s}::get_error_msg;";
	}
	if($STORAGE->replicated()) {
		return "REPLICATED";
	}
	return "NOT_REPLICATED";
}

1;
